﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.Profile;
using CMS.PBDesk.Framework.Web;
using CMS.PBDesk.Business.UserManager;
using PBDesk.Business.Gigya;

namespace PBDesk.Web.CMS.usercontrols.PBDesk.Membership
{
    public partial class AllLogin : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.IsAuthenticated)
            {       
                Literal Literal1 = (Literal)LoginView1.FindControl("Literal1");
                Image ProfileImage = (Image)LoginView1.FindControl("ProfileImage");
                Image LoginProider = (Image)LoginView1.FindControl("LoginProviderImage");
                LinkButton SignoutButton = (LinkButton)LoginView1.FindControl("SignoutButton");
                SignoutButton.Click += new EventHandler(SignoutButton_Click);
                MembershipUser user = System.Web.Security.Membership.GetUser();
                HttpCookie gCookie = CookieManager.GetCookie(CookieHelper.COOKIE_GIGYA_INFO);
                if (user != null && gCookie != null && gCookie.HasKeys)
                {
                    GigyaUser gUser = GigyaHelper.GetGigyaUserFromCookies(gCookie.Values);
                    if (gUser != null)
                    {
                        Literal1.Text = CommonHelper.GetDisplayName(gUser.firstName, gUser.lastName, gUser.nickname, gUser.email);
                        ProfileImage.ImageUrl = gUser.thumbnailURL;
                        LoginProider.ImageUrl = CommonHelper.GetLoginProviderImage(gUser.loginProvider);
                    }
                    else
                    {
                        Literal1.Text = "Gigya User is null";

                    }
                    //var profile = ProfileHelper.GetProfile(user.UserName, true);
                    //if (profile != null)
                    //{
                    //    Literal1.Text = profile.DisplayName;
                    //    ProfileImage.ImageUrl = profile.ThumbnailUrl;
                    //    LoginProider.ImageUrl = CommonHelper.GetLoginProviderImage(profile.LoginProvider);
                    //}
                    //else
                    //    Literal1.Text = "Profile Not Created";
                }
                else
                {
                    //Literal1.Text = userName + " User not created";
                }
            }
        }

        void SignoutButton_Click(object sender, EventArgs e)
        {
            LogonHelper.Logout();
        }

        
    }
}